<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>产品销售提成设定管理</title>
	<meta name="decorator" content="default"/>
	<style type="text/css">
		fieldset{
			display:inline-block;width:100%;
		}
		.ui-field-contain fieldset div.ui-input-text{
			float:left;
			width:60%;
		}
	</style>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#name").focus();
			$("#inputForm").validate({
				rules:{
	                "fixed_money": "ifMoney",
	                "bonus_rate": {
	                 	"range":[0,100] 
	                 }
	            },
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			if("${storeBonusSettingTemplateProduct.product_type}" == 0) {
				$("#type_select_2").css('display', 'none');
			} else {
				$("#type_select_1").css('display', 'none');
			}
			$('#product_type').change(function(){
            	var id =  $(this).val();
            	if(id == 0) {
            		$("#type_select_2").css('display', 'none');
            		$("#type_select_1").css('display', 'block');
            	} else {
            		$("#type_select_1").css('display', 'none');
            		$("#type_select_2").css('display', 'block');
            	}
             });
			var bonus_type = ${storeBonusSettingTemplateProduct.bonus_type};
			if(bonus_type == 0) {
				$("#type_radio_2").css('display', 'none');
	     		$("#type_radio_1").css('display', 'block');
			} else {
				$("#type_radio_1").css('display', 'none');
	     		$("#type_radio_2").css('display', 'block');
			}
     		$('input:radio').click(function(){
             	var id =  $(this).val();
             	if(id == 0) {
             		$("#bonus_rate").val('0');
             		$("#fixed_money").val('0.0');
             		$("#type_radio_2").css('display', 'none');
             		$("#type_radio_1").css('display', 'block');
             		
             	} else {
             		$("#bonus_rate").val('0');
             		$("#fixed_money").val('0.0');
             		$("#type_radio_1").css('display', 'none');
             		$("#type_radio_2").css('display', 'block');
             	}
            });
     		addParentPageNo();
		});
		
		function addParentPageNo() {
			var pageNo = sessionStorage.parentPageNo;
			var id = '${storeBonusSettingTemplateProduct.id}';
			$("#pageNo").val(pageNo);
			var href = "${ctx}/employee/storeBonusSettingTemplateProduct/?type=${storeBonusSettingTemplateProduct.card_type}&pageNo=" +pageNo + "&currentSelectId=" +id;
			$("#return").attr("href", href);
		}
	</script>
</head>
<body>
	<form:form id="inputForm" class="form-input" modelAttribute="storeBonusSettingTemplateProduct" action="${ctx}/employee/storeBonusSettingTemplateProduct/save" method="post">
		<form:hidden path="id"/>
		<input type="hidden" id="pageNo" name="pageNo" />
		<form:hidden path="card_type"/>
		<div class="icon-buttons">
			<a id="return" data-role="button" data-inline="true" data-icon="back" data-iconpos="notext"  href="">返回</a>
			<input type="submit" value="保 存" data-icon="check" data-iconpos="notext"  data-inline="true"/>
		</div>
		<tags:message content="${message}"/>
		<div data-role="fieldcontain">
			<label for="product_type">产品渠道:</label>
			<c:if test="${storeBonusSettingTemplateProduct.id == null}">
				<form:select path="product_type" data-native-menu="false" items="${fns:getDictMap('product_type')}"></form:select>
			</c:if>
			<c:if test="${storeBonusSettingTemplateProduct.id != null}">
				<form:hidden path="product_type"/>
				${fns:getDictLabel(storeBonusSettingTemplateProduct.product_type, "product_type", "")}
			</c:if>
		</div>
		<div data-role="fieldcontain" id="type_select_1">
			<label for="product_category_id">产品渠道分类:</label>
			<c:if test="${storeBonusSettingTemplateProduct.id == null}">
				<form:select path="product_category_id" data-native-menu="false" items="${sellTypeMap}" class="required"></form:select>
			</c:if>
			<c:if test="${storeBonusSettingTemplateProduct.id != null}">
				<form:hidden path="product_category_id"/>
				${fns:getDictLabel(storeBonusSettingTemplateProduct.product_category_id, "product_sell_type", "")}
			</c:if>
		</div>
		<div data-role="fieldcontain" id="type_select_2">
			<input id="categoryId" name="product_category_id_2" type="hidden" value="${storeBonusSettingTemplateProduct.product_category_id}"/>
			<c:if test="${storeBonusSettingTemplateProduct.id == null}">
				<fieldset data-role="controlgroup" data-type="horizontal" data-inline="true">
					<legend>产品分类:</legend>
					<input type="text" readonly id="categoryName" value="${categoryName}" name="categoryName" class="required"/>
					<input type="button" value="选择产品分类" data-inline="true" data-icon="plus" onclick="global.selectDialog('${ctx}/employee/storeBonusSettingTemplateProduct/storeProductCategoryData', this.value, 'category', 'card_type')">
				</fieldset>
			</c:if>
			<c:if test="${storeBonusSettingTemplateProduct.id != null}">
				<label for="categoryId">产品渠道分类:</label>
				${categoryName}
			</c:if>
		</div>
		<div data-role="fieldcontain">
			<fieldset data-role="controlgroup" data-type="horizontal" data-inline="true">
				<legend>提成方式:</legend>
				<form:radiobuttons path="bonus_type" items="${fns:getDictMap('bonus_type')}"/>
			</fieldset>
		</div>
		<div data-role="fieldcontain" id="type_radio_1">
   			<label for="bonus_rate">提成比例(%):</label>
    		<input type="number" id="bonus_rate" value="${fns:changeDisCount(storeBonusSettingTemplateProduct.bonus_rate)}" name="bonus_rate" class="required digits"/>
		</div>
		<div data-role="fieldcontain" id="type_radio_2">
			<label for="fixed_money">提成金额(元):</label>
			<form:input path="fixed_money" htmlEscape="false" class="required"/>
		</div>
	</form:form>
</body>
</html>
